package com.baichang.taoshunda.service.impl;

import com.baichang.taoshunda.dao.FootmarkDao;
import com.baichang.taoshunda.entity.Footmark;
import com.baichang.taoshunda.service.FootmarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ${wushenglu} on 2018/3/12.
 */
@Service
public class FootmarkServiceImpl implements FootmarkService {
    @Autowired
    private FootmarkDao footmarkDao;

    /**
     * 查询我的足迹
     *
     * @param userId   用户编号
     * @param nowPage  当前页
     * @param pageSize 当前条数
     * @param key
     * @return
     */
    @Override
    public List<Map<String, Object>> findFootMark(Integer userId, Integer nowPage, Integer pageSize, String key) {
        return footmarkDao.findFoorMark(userId, nowPage, pageSize, key);
    }

    @Override
    public boolean addFootMark(int userId, Integer goodsId, Integer id) {
        Footmark footmark = new Footmark();
        footmark.setUserId(userId);
        footmark.setBusId(id);
        footmark.setGoodsId(goodsId);
        return footmarkDao.save(footmark) > 0;
    }

    @Override
    public int getCountByUser(int userId, Integer goodsId) {
        return footmarkDao.getCountByUser(userId, goodsId);
    }

    @Override
    public boolean deleteFootMark(Integer footMarkId) {
        return footmarkDao.deleteById(footMarkId) > 0l;
    }

    /**
     * @param userId
     * @param goodsId
     */
    @Override
    public void updateTime(int userId, Integer goodsId) {
        footmarkDao.updateTime(userId, goodsId);
    }

    /**
     * @param userId
     * @return
     */
    @Override
    public boolean deleteAllFootMark(Integer userId) {

        return footmarkDao.deleteAllFootMark(userId);
    }

    @Override
    public boolean deleteSelectedFootMark(String footMarkId) {
        return footmarkDao.deleteSelectedFootMark(footMarkId);
    }
}
